<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Metanode Results</title>
  </head>
  <script src="js/jquery-1.8.3.js"></script>

  <script>
   function gup( name )
   {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
  } 
 
   function processResults(){
	var query = window.location.search.substring(1);
	if (query == "" || query.indexOf("handshake") == -1){
	    alert("Sorry the job id and passcode for job are invalid");
	    return;
	}
	else{
	    handshake = gup("handshake"); 
	    jobid = gup("jobID");  
	    if (jobid == null || jobid == ""){
	      alert("ID is invalid, use the exact link from results email.");	
	      return;
	    } 
	    if (handshake.length < 6){
	      alert("Passcode is invalid, use the exact link from results email.");
	      return;
	      }else{
		$.ajax({
                                type: "POST",
                                url:  "/cgi-bin/results_idare.cgi",
                                data: {'jobID': jobid,'handshake': handshake},
                                success: function(json)
                                {
                                        $("#compound_library_dialog").hide();
                                        if ($.parseJSON(json) == null){
                                                 new Messi('Error on update_spectrum.cgi call, please inform Daniel/Jake with work sequence. Refresh page', {title: 'Server error'});
                                        }
                                        var jo  = $.parseJSON(json);
					var jct = jo["_jobcount"];
					if (jct == "1"){
					sUrl = "http://idare-server.uni.lu/metanodeui/data/" + handshake + ".zip";
			                window.location.assign(sUrl);
					}else{
						alert("JobId/Passcode is invalid, use the exact link from results email.");
					}	
					
				},
				error: function(){
					alert("AJAX:ERROR JobId/Passcode is invalid, use the exact link from results email.");
				}
			});
    	      //sUrl = "http://idare-server.uni.lu/metanodeui/data/" + handshake + ".zip";
	       // window.location.assign(sUrl);
		//window.open(sUrl);
	    }
	}
    }
    </script>
  <body onload="processResults()">
    Content of the document......
  </body>

</html>

